<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="/static/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			#iframe{
				width: 100%;
			}
		</style>
	</head>
	<body>
		<input type="button" id="btn" value="获取" />
		<br />
		<div style="width: 500px;">
			<iframe src="1.html" width="" height="" id="iframe" scrolling="no"></iframe><!--scrolling="no"去掉滚动条,about:confing-->
		</div>			
		
		<script type="text/javascript">
			$(function(){
				var iframe=$('#iframe').get(0);
				/*iframe.contentDocument.open();//打开
				iframe.contentDocument.write(' ');
				iframe.contentDocument.close();*/
				$('#btn').click(function(){
					$.ajax({
						type:"get",
						url:"/type.php",
						success:function(mgs){
							iframe.contentDocument.open();//打开
							//iframe.contentDocument.write('你好');//写
							iframe.contentDocument.write(mgs);
							iframe.contentDocument.close();
							//console.log(iframe.contentDocument.children[0].clientHeight);
							//$('#iframe').height(iframe.contentDocument.children[0].clientHeight+'px');
							iframe.onload=function(){//页面加载完毕就触发
								$('#iframe').height(iframe.contentDocument.children[0].clientHeight+'px');
								//在iframe里的内容加载完毕触发，获取其子元素的内容的高度
								console.log(iframe.contentDocument.children[0].clientHeight);
							}
						}
					});
				});
				
			});
		</script>
	</body>
</html>
